package com.csmht.tododemo.controller.login;

import com.csmht.tododemo.constant.MessageConstant;
import com.csmht.tododemo.mapper.BanMapper;
import com.csmht.tododemo.pojo.dto.UserDTO;
import com.csmht.tododemo.pojo.entity.Ban;
import com.csmht.tododemo.pojo.entity.Role;
import com.csmht.tododemo.pojo.entity.User;
import com.csmht.tododemo.pojo.enumeration.RoleEnum;
import com.csmht.tododemo.properties.JwtProperties;
import com.csmht.tododemo.result.Result;
import com.csmht.tododemo.service.UserService;
import com.csmht.tododemo.until.BaseUnit;
import com.csmht.tododemo.until.JwtUntil;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping
@Slf4j
public class UserController {


    @Resource
    private UserService userService;

    @Resource
    private BanMapper banMapper;

    @Resource
    private JwtProperties jwtProperties;

    @PostMapping("/login")
    public Result<Map<String,Object>> login(@RequestBody UserDTO userLoginDTO) {

        Map<String,Object> map = userService.login(userLoginDTO);


        return Result.success(map);
    }

    @PostMapping("/enroll")
    public Result<Object> register(@RequestBody UserDTO user) {
        userService.register(user);
        return Result.success();
    }


    @GetMapping("/role")
    private Result<Role> findAll() {
        return Result.success(BaseUnit.getCurrentRole());
    }
}
